if(window) {
if(window.AnimationTimer) {
    throw new Error('AnimationTimer 被占用');
} else {

window.AnimationTimer = (function () {
    /**
     * 秒表类
     */
    function StopWatch () { };
    //原型
    StopWatch.prototype = {
        startTime: 0,
        running: false,
        elapsed: undefined,
        //开始计时
        start: function () {
            this.startTime = +new Date();
            this.elapsed = undefined;
            this.running = true;
        },
        //结束计时
        stop: function () {
            this.elapsed = (+new Date()) - this.startTime;
            this.running = false;
        },
        //获取已经过的时间
        getElapsedTime: function () {
            if(this.running) {
                return (+new Date()) - this.startTime;
            } else {
                return this.elapsed;
            }
        },
        //是否正在计时
        isRunning: function () {
            return this.isRunning;
        },
        //重置
        reset: function () {
            this.elapsed = 0;
        }
    }

    /**
     * 动画计时器
     */
    function AnimationTimer (duration) {
        this.duration = duration;
    }

    //原型
    AnimationTimer.prototype = {
        duration: undefined,
        stopwatch: new StopWatch(),
        start: function () {
            this.stopwatch.start();
        },
        stop: function () {
            this.stopwatch.stop();
        },
        getElapsedTime: function () {
            var elapsedTime = this.stopwatch.getElapsedTime();
            if(!this.stopwatch.running) {
                return undefined;
            } else {
                return elapsedTime;
            }
        },
        isRunning: function () {
            return this.stopwatch.isRunning();
        },
        isOver: function () {
            return this.stopwatch.getElapsedTime() > this.duration;
        }
    }

    return AnimationTimer;
}());

}
} else {
throw new Error('环境错误');
}